<template>
    <div class="reportAccept">
        <div class="reportAccept-inner">
            <div class="report-detail">
                <!-- <p class="r-detail-text">尊敬的客户您好!您的报案已受理报案号为<span>36786265355</span></p> -->
                <p class="r-detail-text" v-show="textFlagO">{{textl}}<span>{{reportNo}}</span>{{textr}}</p>
                <p class="r-detail-text" v-show="textFlagT">{{text}}<span>{{reportNo}}</span></p>
                <p class="business-name">{{insurance}}</p>
            </div>
            <div class="close-btn" @click="close">关闭</div>
        </div>
    </div>
</template>
<script>
import {http} from 'utils/request.js';
import api from '../../api/index.js';
import { getStorage } from '../../utils/commonUtil'
export default {
    name: "reportAccept",
    data() {
        return {
            pageOrignCheng:'',
            reportNo:'', //报案号
            textl:'',
            textr:'',
            text:'',
            textFlagO:false,
            textFlagT:false,
            insurance:'',
            carId:'', //车id
            accidentNo:'',
            text:'', //文案
            fromTo:'',  //判断是A车还是B车
            isScan:'',  //判断是单录还是双录
            dutyPercent:'', //判断是全责还是无责
            driverName:'', //司机姓名
            otherDriverName:'' //另一方车主的姓名
        }
    },
    created(){
        //判断是从 A方过来的  还是从 B 方过来的。
        this.pageOrignCheng = sessionStorage.getItem('pageOrignCheng'); // 
        this.insurance = sessionStorage.getItem('insuranceNo');
        this.accidentNo = sessionStorage.getItem('accidentNo');
         //从 A 过来就是 A de carID  从B 过来就是 B 车 的carId
        this.carId = sessionStorage.getItem('carId');
        this.reportNo = '9030000270002152057' + Math.floor(Math.random()*10);
        
        console.log(this.insurance);
        console.log(this.accidentNo);
        console.log(this.carId);
        //console.log(getStorage('insuranceNo'));
        //查询事故信息
        this.searchAccidentInfo();
    },
    mounted(){
        document.title = '报案受理';
        //
    }, 
    methods: {
        getStorage,
        close() {
            this.$router.push("/");
        },
        searchAccidentInfo(){
            let self = this;
            http.get(api.API_ACCIDENT_DETAIL,{
                accidentNo:this.accidentNo
            }).then((res) => {
                const resData = res.resultObj;
                if(res.code == 1){
                    console.log(res.resultObj.carInfoBeans);
                    resData.carInfoBeans.forEach((value,index) => {
                        if(value.carId == self.carId){
                            self.fromTo = value.fromTo;// 1 : A车  0 : B车
                            self.isScan = value.isScan;
                            self.dutyPercent = value.dutyPercent;
                            self.driverName = value.driverName; //司机姓名
                        }else{
                            self.otherDriverName = value.driverName;
                        }
                    });
                    //处理文本
                    this.getDifferentText();
                }else{
                    console.log('');
                }
            }).catch((err) => {
                console.log(err);
            });
            //处理文本
            //this.getDifferentText();
        },
        getDifferentText(){
            //从a方过来
            //if(this.pageOrignCheng == 'a'){
                
                if(this.fromTo == '1'){
                    //A车
                    if(this.isScan == '1' || this.isScan == '2'){
                        //单录 A
                        this.textFlagO = true;
                        this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
                        this.textr = `,请留意保险公司的短信提示!`;
                    }else{
                        //双录
                        if(this.dutyPercent == '1'){
                            //全责   A 全责 双录
                            this.textFlagO = true;
                            this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
                            this.textr = `,请留意保险公司的短信提示!`;
                        }
                        if(this.dutyPercent == '5'){
                            this.textFlagT = true;
                            //无责 A 无责 双录
                            this.text = `尊敬的${this.driverName} 您好! 您已经为全责方车主${this.otherDriverName}完成报案, 报案号为:`;
                        }
                    }
                }else{
                    //B车
                    //if(this.isScan == '1' || this.isScan == '2'){
                        //单录 B
                        this.textFlagO = true;
                        this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
                        this.textr = `,请留意保险公司的短信提示!`;
                   // }else{}
                }
            //}else{
                //从b方过来
                //this.textFlagO = true;
                //this.textl = `尊敬的${this.otherDriverName} 您好! 您的报案已受理, 报案号`;
                //this.textr = `,请留意保险公司的短信提示!`;
            //}
            // if(this.fromTo == '1'){
            //     //A车
            //     if(this.isScan == '1' || this.isScan == '2'){
            //         //单录 A
            //         this.textFlagO = true;
            //         this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
            //         this.textr = `,请留意保险公司的短信提示!`;
            //     }else{
            //         //双录
            //         if(this.dutyPercent == '1'){
            //             //全责   A 全责 双录
            //             this.textFlagO = true;
            //             this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
            //             this.textr = `,请留意保险公司的短信提示!`;
            //         }
            //         if(this.dutyPercent == '5'){
            //             this.textFlagT = true;
            //             //无责 A 无责 双录
            //             this.text = `尊敬的${this.driverName} 您好! 您已经为全责方车主${this.otherDriverName}完成报案, 报案号为:`;
            //         }
            //     }
            // }else{
            //     //B车
            //     if(this.isScan == '1' || this.isScan == '2'){
            //         //单录 B
            //         this.textFlagO = true;
            //         this.textl = `尊敬的${this.driverName} 您好! 您的报案已受理, 报案号`;
            //         this.textr = `,请留意保险公司的短信提示!`;
            //     }else{}
            // }
        }
    }
}
</script>
<style lang="scss" scoped>
    @import "~assets/css/mixin.scss";
    .reportAccept {
        height: 100vh;
        width: 100vw;
        background: #EEEEEE;
        overflow: hidden;
        .reportAccept-inner {
            padding-top: rem(16);
            .report-detail {
                margin:0 auto;
                width: rem(345);
                // height: rem(170);
                padding-bottom: rem(20);
                background: #FFFFFF;
                border-radius: rem(4);
                .r-detail-text{
                    padding:rem(17) rem(40) rem(27) rem(16);
                    font-family: PingFangSC-Regular;
                    font-size: rem(16);
                    color: #5B5B5B;
                    letter-spacing: 0;
                    span {
                        color: red;
                    }
                }
                .business-name {
                    border-top:1px solid  #EEEEEE;
                    padding-top: rem(12);
                    padding-left: rem(22);
                    font-family: PingFangSC-Regular;
                    font-size: rem(14);
                    color: #C9C9C9;
                    letter-spacing: 0;
                }
            }
            .close-btn {
                font-family: PingFangSC-Medium;
                color: #FFFFFF;
                letter-spacing: 0;
                text-align: center;
                position: fixed;
                width: rem(345);
                height: rem(48);
                background: #6794F5;
                border-radius: rem(4);
                font-size: rem(18);
                bottom:rem(20);
                left: 50%;
                line-height: rem(48);
                transform: translateX(-50%);
            }
        }
    }
</style>


